/**
 * 2018年11月27日下午2:37:52
 * @author 谢进财
 */
package com.baihang.project.ds.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baihang.framework.controller.BaseController;
import com.baihang.project.ds.service.SalesManService;

@Controller
@RequestMapping("/salesMan")
public class SalesManController extends BaseController {

	@Autowired
	private SalesManService service;

	@RequestMapping
	public String index() {

		return "/project/ds/salesMan/index2";
	}

	@RequestMapping(value = "/getGrid", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public String getGrid(int page, int pagesize, String sortname, String sortorder) {
		String grid = service.getGrid(page, pagesize, sortname, sortorder);
		// System.out.println(grid);
		return grid;
	}
	
	/**
	 * 认筹表
	 * @param page
	 * @param pagesize
	 * @param sortname
	 * @param sortorder
	 * @return
	 */
	@RequestMapping(value = "/getRcGrid", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public String getRcGrid(int page, int pagesize, String sortname, String sortorder) {
		String grid = service.getRcGrid(page, pagesize, sortname, sortorder);
		// System.out.println(grid);
		return grid;
	}
	
	@RequestMapping(value = "/saveSalesMan", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public String saveSalesMan(String name, String tel) {
		String result="true";
		String msg="保存成功";
		if(!service.saveSalesMan(name, tel)) {
			result="false";
			msg="置业顾问手机已存在！";
		}
		return String.format("{\"result\":\"%s\",\"msg\":\"%s\"}", result,msg);
	}
	
	@RequestMapping(value = "/saveRenChou", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public String saveRenChou(String name, String money) {
		String result="true";
		String msg="保存成功";
		if(!service.saveRenChou(name, money)) {
			result="false";
			msg="认筹金额已经存在";
		}
		return String.format("{\"result\":\"%s\",\"msg\":\"%s\"}", result,msg);
	}
	@RequestMapping(value = "/deleteSalesMan", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public String deleteSalesMan(int id) {
		String result="true";
		String msg="删除成功";
		if(!service.deleteSalesMan(id)) {
			result="false";
			msg="删除失败";
		}
		return String.format("{\"result\":\"%s\",\"msg\":\"%s\"}", result,msg);
	}
	@RequestMapping(value = "/deleteRenChou", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public String deleteRenChou(int id) {
		String result="true";
		String msg="删除成功";
		if(!service.deleteRenChou(id)) {
			result="false";
			msg="删除失败";
		}
		return String.format("{\"result\":\"%s\",\"msg\":\"%s\"}", result,msg);
	}
}
